package com.wuzao.TimeTest;

import cn.hutool.core.util.StrUtil;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.TemporalAdjusters;
import java.util.*;

public class CalendarTest {
    public static void main(String[] args) {
        int months = 3; // 持续几个月

        List<LocalDateTime> result = getDatesByDaysOfWeek(Arrays.asList(1, 2), months);

        // 打印结果
        System.out.println("目标星期几的日期如下：");
        for (LocalDateTime dateTime : result) {
            System.out.println(dateTime);
        }
    }

    public static List<LocalDateTime> getDatesByDaysOfWeek(List<Integer> targetDaysOfWeek, int months) {
        List<LocalDateTime> result = new ArrayList<>();

        LocalDateTime currentDate = LocalDateTime.now();
        LocalDateTime targetDate = currentDate.plusMonths(months);

        while (currentDate.isBefore(targetDate)){
            currentDate = currentDate.plusDays(1);
            LocalDateTime finalCurrentDate = currentDate;
            if(targetDaysOfWeek.stream().anyMatch(i -> i == finalCurrentDate.getDayOfWeek().getValue())){
                currentDate = currentDate.withHour(1);
                result.add(currentDate);
            }


        }
        return result;
    }
}
